package com.fz.controller;

import com.alibaba.fastjson.JSON;
import com.fz.entity.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by webrx on 2017/6/27.
 */
@Controller
public class Json {

    @RequestMapping("/view") @ResponseBody
    public String[] view(){
        String[] addr =new String[]{"上海","洛阳","开封"};
        return addr;
    }

    @RequestMapping("/view02") @ResponseBody
    public List<String> view02(){
        List<String> addr =new ArrayList<String>();
        addr.add("北京");
        addr.add("武汉");
        addr.add("上海");
        return addr;
    }

    @RequestMapping("/view03") @ResponseBody
    public Book view03(){
        return new Book(10,"java项目",50);
    }


    @RequestMapping("/view04") @ResponseBody
    public String view04(){
      Book book = new Book(10,"php课程",20);
      return JSON.toJSONString(book);

    }


    @RequestMapping(value = "view05",produces = {"application/json;charset=utf-8"}) @ResponseBody
    public String view05(){
        List<String> addr =new ArrayList<String>();
        addr.add("北京");
        addr.add("武汉");
        addr.add("上海");
        return JSON.toJSONString(addr);
    }

    @RequestMapping(value = "view06",produces = {"application/json;charset=utf-8"}) @ResponseBody
    public String times(){
       String times = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date()) ;
       return times;
    }
}
